//获取应用实例
const app = getApp();
Page({
	data: {
		imgpath: app.setting.apiimgpath,
		gid:'',
		inputVal:1,
		allData:'',
		price:'',
		allIntegral:''
	},
	onLoad:function(option){
		var that = this;
		that.setData({
			gid:option.gid
		});
		//商品详情
		app.request('/api/Goods/getGoodsInfo', {goodsid:option.gid}, function(res){
			if(res.code == '0'){
				that.setData({
					allData:res.data,
					allIntegral:res.data.price,
					price:res.data.price
				})
			}
		});
	},
	backIndex:function(){
		wx.switchTab({
			url:'/pages/index/index'
		})
	},
	inputNumber:function(e){
		this.setData({
			inputVal:e.detail.value
		});
	},
	reduceNumber:function(){
		var that = this;
		if(that.data.inputVal==1 || that.data.inputVal<1){
			wx.showToast({
				title:'数量最少为1',
				icon:'none'
			})
			that.data.inputVal = 1;			
		}else{
			that.data.inputVal--;
			var renum = that.data.price*that.data.inputVal;
			that.setData({
				inputVal:that.data.inputVal,
				allIntegral:renum
			});
		}
	},
	addNumber:function(){
		var that = this;
		that.data.inputVal++;
		var addnum = that.data.price * that.data.inputVal;
		that.setData({
			inputVal:that.data.inputVal,
			allIntegral:addnum
		});
	},
	trueExchange:function(){	
		var that = this;
		//商品列表
		app.request('/api/Goods/exchange', {gid:that.data.gid,number:that.data.inputVal}, function(res){
			if(res.code == '0'){
				wx.navigateTo({
					url: '/pages/integralmall/integralmall'
				})
			}else{
				wx.showToast({
					title:res.msg,
					icon:'none'
				})
			}
		});
	}
})